<?php

include 'D:\wangkai\汇付宝phpAPI\客户中心RSA2 PHP\Util.php';
use function Util\PicToTow;
use function Util\Postformdata;
use function Util\ASCIIAZ;
use function Util\RSA2sign;
use function Util\verifysign;



// 本地文件路径
$filePath = 'D:/bizhi/ceshi123.zip';
//图片转二进制处理
$file_signd = PicToTow($filePath);
$t=time();
$timestampd=date('Y-m-d H:i:s', $t);


/*
请求参数
*/

$app_id='hy20240426110700440847';
$charset='utf-8';
$credential_type='01';
$file_sign=$file_signd;
$method='customer.media.upload';
$format='json';
$sign_type='RSA2';
$version='1.0';
$timestamp=$timestampd;
$arrayData = array(
    'app_id' => $app_id,
    'credential_type' => $credential_type,
    'charset' => $charset,
    'method' => $method,
    'format' => $format,
    'sign_type' => $sign_type,
    'version' => $version,
    'timestamp' => $timestamp,
    'file_sign' => $file_sign
);

/*
拼接签名串
*/


$signatureContent = ASCIIAZ($arrayData);
echo "签名前参数：".$signatureContent.PHP_EOL;
echo "<br/><hr>";

/*
签名
*/


$sign = RSA2sign($signatureContent);
// 构造 POST 请求数据
$post_string = array(
    'charset' => $charset,
    'credential_type' => $credential_type,
    'method' => $method,
    'format' => $format,
    'sign' => $sign,
    'file_sign' => $file_sign,
    'app_id' => $app_id,
    'sign_type' => $sign_type,
    'version' => $version,
    'timestamp' => $timestamp,
    'file_content'   => new \CURLFile($filePath)  // 添加文件字段，使用 CURLFile 类
);

// 目标 URL
$url = 'https://openapi.heepay.com/customer-api/customer.media.upload';  //调用接口的平台服务地址


$Response = Postformdata($url,$post_string);
$response = json_decode($Response, true);
$bizContentJson = json_encode(array('file_id' => $response['biz_content']['file_id']), JSON_UNESCAPED_UNICODE + JSON_UNESCAPED_SLASHES);
$queryString = 'biz_content=' . $bizContentJson . '&code=' . urlencode($response['code']) . '&msg=' . urlencode($response['msg']) .'&trace_id=' . urlencode($response['trace_id']);

//同步返回验签
if($response['code']===10000){

    echo "响应结果------->" .$Response . PHP_EOL;
    echo "验签串------>" .$queryString .PHP_EOL;
    verifysign($queryString,$response['sign']);
}
else
{
    echo $Response;
}
?>

